﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Janksen.ValidationHelper;
using Janksen.Mapping;
using System.Reflection;
using Web.Entity;
using Janksen.Mapping.EntityExtend;
using System.Data;
using System.Data.SqlClient;
using Janksen.DataAccess;
using System.Configuration;

namespace Web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // string test = "asdfasdfasdfwqerqewgsdv";

            //// test.InitValidation(false).IsTypeOf(typeof(string)).LongerThan(4).ShorterThan(6).LengthBetween(4, 6).RegexValidate("^[0-9]$");

            // //CodeTest.User.CodeDomTest();

            // User user = new User();
            // user.Age = 10;

            // PropertyInfo[] pro = typeof(User).GetProperties();

            // DataTable table;
            // table = MakeNamesTable();

            // // Once a table has been created, use the 
            // // NewRow to create a DataRow.
            // DataRow row;
            // row = table.NewRow();

            // // Then add the new row to the collection.
            // row["UserName"] = "John";
            // row["RealName"] = "Smith";
            // table.Rows.Add(row);

            //  Type type = typeof(Web.Entity.User).ReflectedType;

            // IEntityExtend obj = EntityExtendHelper.GetInstance<Web.Entity.User>();

            // IEntityExtend obj2=EntityExtendHelper.GetInstance<Web.Entity.Group>();

            // IEntityExtend obj3 = EntityExtendHelper.GetInstance<Web.Entity.Group>();

            // IEntityExtend obj4 = EntityExtendHelper.GetInstance<Web.Entity.User>(); 

            //obj.SetFieldsValue(row);
            //obj.GetSqlParamsValue(user);


            SqlDataReader dataReader = SqlHelper.ExecuteReader(ConfigurationManager.ConnectionStrings["connString"].ToString(), CommandType.Text, "select * from [User]");

            DataTable dt = SqlHelper.ExecuteDataset(ConfigurationManager.ConnectionStrings["connString"].ToString(), CommandType.Text, "select * from [User]").Tables[0];

            List<Web.Entity.User> lst = Janksen.Mapping.LoadData.LoadForObjectList<Web.Entity.User>(dt);

            Web.Entity.User user = Janksen.Mapping.LoadData.LoadForObject<Web.Entity.User>(dataReader);



        }


        private DataTable MakeNamesTable()
        {
            // Create a new DataTable titled 'Names.'
            DataTable namesTable = new DataTable("Names");

            // Add three column objects to the table.
            DataColumn idColumn = new DataColumn();
            idColumn.DataType = System.Type.GetType("System.Int32");
            idColumn.ColumnName = "Age";
            idColumn.DefaultValue = 10;
            namesTable.Columns.Add(idColumn);

            DataColumn fNameColumn = new DataColumn();
            fNameColumn.DataType = System.Type.GetType("System.String");
            fNameColumn.ColumnName = "UserName";
            fNameColumn.DefaultValue = "Fname";
            namesTable.Columns.Add(fNameColumn);

            DataColumn lNameColumn = new DataColumn();
            lNameColumn.DataType = System.Type.GetType("System.String");
            lNameColumn.ColumnName = "RealName";
            namesTable.Columns.Add(lNameColumn);

            // Create an array for DataColumn objects.
            DataColumn[] keys = new DataColumn[1];
            keys[0] = idColumn;
            namesTable.PrimaryKey = keys;

            // Return the new DataTable.
            return namesTable;
        }


    }
}
